package com.cysyz.mylib.dao;

import java.util.List;

public class PagingResult<T> {
	private List<T> records;
	private Long totalRecords;
	private long currentPage;
	private int resultPerpage;
	
	private long totalPage;
	private long nextPage;
	private long prePage;

	public PagingResult(List<T> records, long totalRecords, long currentPage,
			int resultPerpage) {
		super();
		this.records = records;
		this.totalRecords = totalRecords;
		this.currentPage = currentPage;
		this.resultPerpage = resultPerpage;
		checkStatus();
	}
	
	private void checkStatus() {
		this.totalPage = totalRecords%resultPerpage == 0 ? totalRecords/resultPerpage : totalRecords/resultPerpage + 1;  
		if (currentPage > totalPage) {
			currentPage = totalPage;
		} else if (currentPage < 1) {
			currentPage = 1l;
		}
		nextPage = currentPage + 1;
		prePage = currentPage - 1;
		
		if (currentPage ==1 ) {
			prePage = 1;
		} else if(currentPage == totalPage){
			nextPage= totalPage;
		}
	}
	
	public void setTotalRecords(Long totalRecords) {
		this.totalRecords = totalRecords;
	}
	
	public List<T> getRecords() {
		return records;
	}

	public long getTotalRecords() {
		return totalRecords;
	}
	
	public long getCurrentPage() {
		return currentPage;
	}

	public int getResultPerpage() {
		return resultPerpage;
	}

	public long getTotalPage() {
		return totalPage;
	}
	
	public long getNextPage() {
		return nextPage;
	}

	public long getPrePage() {
		return prePage;
	}

}